<!DOCTYPE html>
<html>
<head>
  <link rel="chrome-webstore-item">
</head>
<body>
<script>
  console.log('Page loaded');

  function runTest(galleryUrl) {
    console.log('In runTest');

    var storeUrl = galleryUrl + '/detail/ecglahbcnmdpdciemllbhojghbkagdje';
    // Link URL has to be generated dynamically in order to include the right
    // port number. The ID corresponds to the data in the "extension" directory.
    document.getElementsByTagName('link')[0].href = storeUrl;

    var callback = function() {
      console.log('did not expect install to complete');
      window.domAutomationController.send(false);
    };

    try {
      chrome.webstore.install(undefined, callback, callback);
    } catch (e) {
      console.log('unexpected exception: ' + e);
      window.domAutomationController.send(false);
      throw e;
    }
    try {
      chrome.webstore.install(undefined, callback, callback);
    } catch (e) {
      console.log('Ran test, sending response');
      window.domAutomationController.send(
          e.message.indexOf('already pending') != -1);
    }
  }
</script>

</body>
</html>
